﻿@using Orchard.Utility.Extensions;
@using Contrib.Taxonomies.Models;
@using Contrib.Taxonomies.Helpers;

@{
    Style.Include("admin-taxonomy.css");
    int level=0;
    int firstLevel = -1;
}

<div class="taxonomy-menu">
<ul class="terms">
	@foreach (TermPart term in Model.Terms) {
     if(firstLevel == -1){
         firstLevel = term.GetLevels();
     }
     var text = Model.ContentPart.DisplayContentCount ? (string)term.Name + T(" ({0})", term.Count).Text : (string)term.Name;
		if(term.GetLevels() - firstLevel > level) {
			level++;
			@:<ul class="terms">
		}
		    @:</li>
		
		if(term.GetLevels() - firstLevel < level) {
			level--;
			@:</ul>
		}

		@:<li>
			@Html.ItemDisplayLink(text, term.ContentItem)
 }
        
		</li>
	@for (int i = 0; i < level; i++) {
	@:</ul>
	}
</ul>
</div>